package com.zmn.brs.dubbo.impl.record;

import com.zmn.brs.business.interfaces.record.OperateRecordNewBService;
import com.zmn.brs.common.enums.EventEnum;
import com.zmn.brs.common.model.dio.OperateRecordDIO;
import com.zmn.brs.common.model.mq.OperateRecordMq;
import com.zmn.brs.dubbo.constant.DubboConsts;
import com.zmn.brs.dubbo.interfaces.record.OperateEventModifyRemoteService;
import com.zmn.brs.model.result.OperateRecordResult;
import com.zmn.common.dto2.ResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 类描述：安全监控事件操作接口实现
 * @author zhangyao
 * @since 2021/04/28 18:32
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 6000, retries = -1, version = DubboConsts.INTERFACE_VERSION)
public class OperateEventModifyRemoteServiceImpl implements OperateEventModifyRemoteService {

    private static final String TAG = "操作事件操作接口";

    @Resource
    OperateRecordNewBService operateRecordBusinessService;

    @Override
    public ResponseDTO<Boolean> operateEventMonitor(OperateRecordDIO operateRecord) {
        log.info("[{}],受到调用:{}", TAG, operateRecord);
        EventEnum event = operateRecord.getEvent();
        if (event == null) {
            return ResponseDTO.success(false, "未匹配到对应的事件");
        }
        OperateRecordMq recordMq = OperateRecordMq.builder()
                .plat(operateRecord.getPlat())
                .channelId(operateRecord.getChannelId())
                .objectIdentity(operateRecord.getObjectIdentity())
                .objectId(operateRecord.getObjectId())
                .objectMobile(operateRecord.getObjectMobile())
                .event(event)
                .objectIp(operateRecord.getObjectIp())
                .createTime(new Date())
                .build();
        if (recordMq.getPlat() != null) {
            // 转换事件编码
            event = EventEnum.transformEventEnum(event, recordMq.getPlat().getCode());
            recordMq.setEvent(event);
        }
        OperateRecordResult result = operateRecordBusinessService.eventTriggering(recordMq);
        return ResponseDTO.success(result.getResult());
    }
}
